package com.taotao.observer1.impl;

import com.taotao.observer1.AbstractSubject;
import com.taotao.observer1.Observer;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: wangjin
 * @CreateTime: 2022-07-03  10:38
 */
@Component
public class MsgSubject  implements AbstractSubject {
    private List<Observer> observers=new ArrayList<>();
    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void delObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyAll(String message) {
        observers.forEach(o->{
            o.update(message);
        });
    }
}
